num = input()
if len(num) == 4:
    def isEasy(x):
        if x == 1: return False
        s = True
        k = x - 1
        while k > 1:
            if not x % k:
                s = False
                break
            k -= 1
        return s

    c = []
    for i in range(len(num)):
        for k in range(i + 1, len(num) + 1):
            x = int(num[i:k])
            if isEasy(x):
                c += [x]
    print(max(c) if c else 0)
else:
    print(0)



